function Q = getQ(n_seg, n_order, ts)
    Q = [];
    N=(n_order+1)/2; % 所求的是N次导数
    for k = 1:n_seg
        %#####################################################
        % STEP 1.1: calculate Q_k of the k-th segment 
        %
        %
        %
        %
        T = ts(k);
        Q_k=zeros(2*N,2*N);
        for i = N:2*N-1
            for j=N:2*N-1
                Q_k(i+1,j+1)=factorial(i)/factorial(i-N)*factorial(j)/factorial(j-N)*T^(i+j-2*N+1)/(i+j-2*N+1);
            end
        end
        Q = blkdiag(Q, Q_k); % 产生对角矩阵 
    end
end